<%@ page language="java" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>城市区域管理</title>
    <meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' name='viewport'>
    <jsp:include page="../com/header.jsp"></jsp:include>
    <script type="text/javascript" src="../../js/comm/listcomm.js"></script>
    <script type="text/javascript" src="../../js/comm/editcomm.js"></script>
    <script	type="text/javascript" src="../../js/nice-validator/jquery.validator.min.js"></script>
    <script type="text/javascript">
        var contentUrl = root + "cms/sysArea/findSysAreaNEStatusPage";
        var editUrl = 'sysAreaEdit.jsp?id=';
        var operateUrl = root + 'cms/sysArea/operateSysAreaByIds';
        var findInsCountByCityId = root + 'cms/sysArea/findInsCountByCityId';
        function getfilter() {
            var _jsonFilter = "{";
            if ($("#search_areaName").val() && $("#search_areaName").val().length > 0) {
                _jsonFilter += "'search_LIKEPINYIN_areaName':'" + $("#search_areaName").val().replace("'", "\"") + "',";
            }
            if ($("#search_areaType").val() && $("#search_areaType").val().length > 0) {
                _jsonFilter += "'search_EQ_areaType':'" + $("#search_areaType").val().replace("'", "\"") + "',";
            }
            if ($("#search_isHot").val() && $("#search_isHot").val().length > 0) {
                _jsonFilter += "'search_EQ_isHot':'" + $("#search_isHot").val().replace("'", "\"") + "',";
            }
            if (_jsonFilter != "{") {
                _jsonFilter = _jsonFilter.substring(0, _jsonFilter.length - 1);
            }
            _jsonFilter += "}";
            return _jsonFilter;
        }


        $(document).ready(function () {
            $("#deleteSome_cityId").click(function () {
                del_city();
            });
        });

        /** 删除事件 */
        function del_city() {
            var checkError = false;
            var delArray = [];
            $(".ckSelect").each(function () {
                var check = $(this).is(':checked');
                if (check) {
                    var _id = $(this).attr("ckId");
                    delArray.push(_id);
                }
            });
            if (delArray.length == 0) {
                myAlert("请选择要删除的项");
                return;
            }
            if (delArray.length > 1) {
                myAlert("分类一次只能删除一项!");
                return;
            }

            var ckType = $("#ckType").val();

            //confirm start
            var jc = $.confirm({
                content: function () {
                    var self = this;
                    return $.ajax({
                        url: findInsCountByCityId,
                        dataType: 'json',
                        method: 'post',
                        data: {
                            cityId: delArray[0]
                        }
                    }).done(function (data) {
                        if (data.code == 1) {
                            if (data.object > 0) {
                                self.setContent("该城市中已经存在机构数据"+ data.object +"条，不能删除");
                                self.setContentAppend("!");
                                jc.buttons.danger.hide();
                            } else {
                                jc.close();
                                del(operateUrl + '?modelIds=');
                            }
                        } else {
                            jc.close();
                            myAlert(data.msg);
                        }
                    }).fail(function () {
                        jc.close();
                        self.setContent('request wrong.');
                    });
                },
                buttons: {
                    danger: {
                        action: function () {
                            jc.close();
                            del(url);
                        }
                    }
                }
            });
            //confirm end
        }
        
    </script>
</head>
<body>
<section>
    <div>
        <div class="col-xs-12">
            <div class="box">
                <form id="search_form" class="form-horizontal">
                    <div class="tabSelect" id="selectHeadId">
                        <br>
                        <div class="form-group  col-md-3 search-form">
                            <label class="col-md-4 control-label controls" for="">区域名称：</label>
                            <div class="col-md-8">
                                <input type="text" placeholder="区域名称" class="form-control input-sm" id="search_areaName"
                                       name="areaName"/>
                            </div>
                        </div>
                        <div class="form-group  col-md-3 search-form">
                            <label class="col-md-4 control-label controls" for="">国内国外：</label>
                            <div class="col-md-8">
                                <select class="form-control input-sm" id="search_areaType" name="areaType">
                                    <option  value="">请选择</option>
                                    <option  value="0">国内</option>
                                    <option  value="1">国外</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group  col-md-3 search-form">
                            <label class="col-md-4 control-label controls" for="">是否热点城市：</label>
                            <div class="col-md-8">
                                <select class="form-control input-sm" id="search_isHot" name="isHot">
                                    <option  value="">请选择</option>
                                    <option  value="1">热门</option>
                                    <option  value="0">普通</option>
                                </select>
                            </div>
                        </div>
                        <input type="button" value="查询" id="search" class="btn btn-primary searchBtn">
                    </div>
                </form>
                <div class="box-body table-responsive" style="clear:both;">
                    <input type="button" value="新增" id="addSome" class="btn btn-success">
                    <input type="button" value="编辑" id="updateSome" class="btn btn-info">
                    <input type="button" value="删除" id="deleteSome_cityId" class="btn btn-danger">
                </div>
                <div class="box-body table-responsive">
                    <table id="example2" class="table table-bordered table-hover">
                        <thead>
                        <tr>
                            <th width="30"><input type="checkbox" id="_selectAll"/></th>
                            <th width="80">城市名称</th>
                            <th width="80">国内国外</th>
                            <th width="80">是否热门城市</th>
                            <th width="80">首字母</th>
                            <th width="80">排序id</th>
                            <th width="80">状态</th>
                        </tr>
                        </thead>
                        <!-- 表格内容 start -->
                        <tbody id="mycontent"></tbody>
                        <!-- 表格内容 end -->
                    </table>
                    <!-- 分页标签 start -->
                    <div class="row page_big_div" id="displayPage"></div>
                    <!-- 分页标签 end -->
                    <script id="tableContentTmple" type="text/x-jsrender">
								<tr>
									<td><input id="ck_{{:id}}" ckId="{{:id}}" ckStatus="{{:status}}" class="ckSelect" type="checkbox" /></td>
									<td>{{:areaName}}</td>
									<td>{{if areaType==0}}国内{{else}}国外{{/if}}</td>
									<td>{{if isHot}}热门{{else}}普通{{/if}}</td>
									<td>{{:letter}}</td>
									<td>{{:orderNum}}</td>
									<td>{{if status==1}}正常{{else status==2}}已发布{{else status==3}}已删除{{else status==-1}}已锁定{{else}}无效{{/if}}</td>
								</tr>

                    </script>
                </div>
            </div>
        </div>
</section>
</body>
</html>